package com.fsnbigdata.domain.security;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fsnbigdata.domain.Organism;
import io.springlets.format.EntityFormat;
import org.springframework.security.core.GrantedAuthority;

import javax.persistence.*;

/**
 * Created by fan.jin on 2016-11-03.
 */

@Entity
public class Authority implements GrantedAuthority {

    public static final Authority USER_ADMIN = new Authority( "ROLE_USER_ADMIN");

    public static final Authority USER = new Authority( "ROLE_USER");

    public static final Authority DB_ORGANISM = new Authority( "DB_ORGANISM");

    public static final Authority DB_SPECIMEN = new Authority("DB_SPECIMEN");

    public static final Authority DB_PARK = new Authority("DB_PARK");

    public static final Authority DB_ECOSYSTEM = new Authority("DB_ECOSYSTEM");

    public static final Authority DB_ES_CS = new Authority("DB_ES_CS");

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    Long id;

    @Column(name="name")
    String name;

    @JsonIgnore
    @ManyToOne(fetch = FetchType.EAGER)
    @EntityFormat
    private User user;

    public Authority(Long id, String name) {
        this.id = id;
        this.name = name;
    }

    public Authority(String name) {
        this.name = name;
    }

    public Authority() {
    }

    @Override
    public String getAuthority() {
        return name;
    }

    void setAuthority(String authority){
        this.name = authority;
    }

    public void setName(String name) {
        this.name = name;
    }

    @JsonIgnore
    public String getName() {
        return name;
    }

    @JsonIgnore
    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public User getUser() {
        return user;
    }

    public void setUser(User user) {
        this.user = user;
    }
}
